﻿@{
    ViewBag.Title = "管理员";
}

@section SideNav{@Html.Partial("SideNavPartialView")}
<ol class="breadcrumb">
    <li><span class="glyphicon glyphicon-home"></span>  @Html.ActionLink("首页", "Index", "Home")</li>
    <li class="active">@Html.ActionLink("权限列表", "Index", "Permission")</li>
</ol>

<table id="permissiongrid"></table>
<script type="text/javascript">
    $(document).ready(function () {
        var $table = $('#permissiongrid');
        $table.bootstrapTable({
            toolbar: "#toolbar",
            showRefresh: true,
            showColumns: true,
            showFooter: true,
            method: "post",
            pageNumber: 1,
            pageSize: 10,
            pagination: true,
            sidePagination: "server",
            pageList: "[5, 10, 20, 50, 100]",
            url: "@Url.Action("PageList")",
            contentType: "application/x-www-form-urlencoded",
            queryParams: queryParams,
            queryParamsType: "limit", //参数格式,发送标准的RESTFul类型的参数请求\
            columns: [
                    { title: "state", checkbox: true },
                    { title: "ID", field: "PermissionID" },
                    { title: "控制器名称", field: "ControllerName" },
                    { title: "动作名称", field: "ActionName" },
                    { title: "控制器", field: "Controller" },
                    { title: "动作", field: "Action" },
                    { title: "控制器排序", field: "ControllerNo", visible: false },
                    { title: "动作排序", field: "ActionNo", visible: false },
                    { title: "创建时间", field: "Cteated_at", formatter: function (value) { return moment(value).format("YYYY-MM-DD HH:mm:ss") } },
                    { title: "更新时间", field: "Updated_at", formatter: function (value) { return moment(value).format("YYYY-MM-DD HH:mm:ss") }, visible: false },
                    {
                        title: "操作", field: "PermissionID", formatter: function (value) {
                            return "<a class='btn btn-sm btn-primary' href='#' data-method='Modify' data-value=" + value + ">编辑</a>"
                        }
                    }
            ],
            onAll: function (name, args) {
                if ((name == "load-success.bs.table") || (name == "column-switch.bs.table")) {
                    //修改
                    $("a[data-method='Modify']").click(function () {
                        var id = $(this).attr("data-value");
                        var modifyDialog = new BootstrapDialog({
                            title: "<span class='glyphicon glyphicon-user'></span>修改权限信息",
                            message: function (dialog) {
                                var $message = $('<div></div>');
                                var pageToLoad = dialog.getData('pageToLoad');
                                $message.load(pageToLoad);

                                return $message;
                            },
                            data: {
                                'pageToLoad': '@Url.Action("Modify")/' + id
                            },
                            buttons: [{
                                icon: "glyphicon glyphicon-plus",
                                label: "保存",
                                action: function (dialogItself) {
                                    $.post($("form").attr("action"), $("form").serializeArray(), function (data) {
                                        if (data.Code == 1) {
                                            BootstrapDialog.show({
                                                message: data.Message,
                                                buttons: [{
                                                    icon: "glyphicon glyphicon-ok",
                                                    label: "确定",
                                                    action: function (dialogItself) {
                                                        $table.bootstrapTable("refresh");
                                                        dialogItself.close();
                                                        modifyDialog.close();
                                                    }
                                                }]

                                            });
                                        }
                                        else BootstrapDialog.alert(data.Message);
                                    }, "json");
                                    $("form").validate();
                                }
                            }, {
                                icon: "glyphicon glyphicon-remove",
                                label: "关闭",
                                action: function (dialogItself) {
                                    dialogItself.close();
                                }
                            }]
                        });
                        modifyDialog.open();
                    });
                    //修改结束
                }
            }
        })
    })

    function queryParams(params) {
        var temp = {
            pageNumber: params.offset,
            pageSize: params.limit,
            //name: document.getElementById("search").value
        };
        return temp;
    }
</script>